package com.uchiha.nova.mainService.wrapper;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.uchiha.nova.core.model.entity.DictEntity;
import com.uchiha.nova.core.model.vo.DictVO;
import com.uchiha.nova.core.tool.support.BaseEntityWrapper;
import com.uchiha.nova.core.tool.util.SpringUtil;
import com.uchiha.nova.mainService.service.IDictService;

import java.util.List;
import java.util.stream.Collectors;
/**
 * 系统字典 包装类,返回视图层所需的字段
 *
 * @author Uchihashiamu
 */
public class DictWrapper extends BaseEntityWrapper<DictEntity, DictVO>  {
  
  IDictService dictService = SpringUtil.getBean(IDictService.class);
  
	public static DictWrapper build() {
		return new DictWrapper();
 	}

	@Override
	public DictVO entityVO(DictEntity dictEntity) {
		DictVO dictVO = new DictVO();
		BeanUtil.copyProperties(dictEntity, dictVO);

		return dictVO;
	}
	public List<DictVO> listVO(List<DictEntity> list) {
		List<DictVO> collect = list.stream().map(item -> {
            DictVO dictVO = new DictVO();
		    BeanUtil.copyProperties(item, dictVO);			
			return dictVO;
		}).collect(Collectors.toList());
		return collect;
    // return ForestNodeMerger.merge(collect);
	}
  
  	@Override
	public IPage<DictVO> pageVO(IPage<DictEntity> pages) {
		IPage<DictVO> page = pages.convert(item->{
            DictVO dictVO = new DictVO();
		    BeanUtil.copyProperties(item, dictVO);			
			return dictVO;
		});
		return page;
	}
}
